package cn.lili.controller.feign.auth;

import cn.lili.common.security.AuthUser;
import cn.lili.common.security.enums.SceneEnums;
import cn.lili.common.security.token.Token;
import cn.lili.modules.auth.client.AuthClient;
import cn.lili.modules.auth.service.AuthService;
import cn.lili.modules.member.entity.dos.User;
import cn.lili.modules.token.TokenGenerate;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

/**
 * Authclient实现
 *
 * @author Chopper
 * @version v1.0
 * 2022-09-01 15:11
 */
@RestController
@RequiredArgsConstructor
public class AuthFeignController implements AuthClient {

    private final TokenGenerate tokenGenerate;

    private final AuthService authService;

    @Override
    public Token createToken(User user, boolean longTerm) {
        return tokenGenerate.generateToken(user, longTerm);
    }

    @Override
    public Token refreshToken(String refreshToken) {
        return tokenGenerate.refreshToken(refreshToken);
    }

    @Override
    public void logout(SceneEnums sceneEnums) {
        authService.logout(sceneEnums);
    }

    @Override
    public void resetUserPermissionMap(AuthUser authUser) {
        tokenGenerate.handlerPermission(authUser);
    }
}
